﻿Imports System.Windows.Controls.Primitives

Namespace Controls
    Public Class LSWMsgBox
        Public Event Completed As Action(Of Boolean)
        Dim pop As New Popup
        Shared clickCount As Integer = 0
        Public Sub ShowExitMsg()
            Show("再按一次离开")
        End Sub
        Public Sub Show(msg As String)
            If clickCount > 0 Then
                RaiseEvent Completed(True)
            Else
                clickCount += 1
                RaiseEvent Completed(False)

                Dim tips As New LSWMessboxControl
                tips.Text = msg

                pop.Height = 65
                pop.Width = 200
                pop.Margin = New Thickness(140, 380, 0, 0)
                pop.IsOpen = False
                pop.Child = tips
                Dim story As New Storyboard
                Dim topAnimation As New DoubleAnimation
                topAnimation.From = 0
                topAnimation.To = 1
                Storyboard.SetTarget(topAnimation, tips)
                Storyboard.SetTargetProperty(topAnimation, New PropertyPath("(UIElement.Opacity)"))

                pop.IsOpen = True
                story.Begin()
                story.Duration = New Duration(New TimeSpan(0, 0, 2))
                story.BeginTime = New TimeSpan(0, 0, 0, 0, 1)
                AddHandler story.Completed, Sub(s1, e1)
                                                clickCount = 0
                                                pop.IsOpen = False
                                                story.Stop()
                                            End Sub
            End If
        End Sub
    End Class
End Namespace